/*********************************************************************************
 *      Copyright:  (C) 2024 LiYi<1751425323@qq.com>
 *                  All rights reserved.
 *
 *       Filename:  database.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(25/04/24)
 *         Author:  LiYi <1751425323@qq.com>
 *      ChangeLog:  1, Release initial version on "25/04/24 09:17:32"
 *                 
 ********************************************************************************/
#include <stdio.h>
#include <string.h>

#include "sqlite3.h"
#include "database.h"

#define TABLE  "my_temperature"

void server_lib(char *buf)
{
	char    buff[100] = "../server_library/server_data_lib.db";
	int             rc;
	char    sql[256];
	sqlite3 *db;

	if(sqlite3_open(buff,&db) != SQLITE_OK)
	{
		printf("sqlite3_open failure: %s\n",sqlite3_errmsg(db));
		sqlite3_close(db);
	}

	sprintf(sql,"CREATE TABLE IF NOT EXISTS " TABLE "(TEMP TEXT NOT NULL);");
	sqlite3_exec(db,sql,0,0,0);
	memset(sql,0,sizeof(sql));

	sprintf(sql,"insert into %s values('%s');",TABLE,buf);
	if(sqlite3_exec(db,sql,0,0,0) != SQLITE_OK)
	{
		printf("sqlite3_exec failure: %s\n",sqlite3_errmsg(db));
		sqlite3_close(db);
	}


}
